package com.badibadi.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.badibadi.activity.AddingRecordFirstActivity.Friend_Item_Adapter;
import com.badibadi.infos.Discuss;
import com.badibadi.infos.ImageAttribute;
import com.badibadi.infos.ModifyRecordDanjiModel;
import com.badibadi.infos.MyFriendsModel;
import com.badibadi.infos.Results;
import com.badibadi.infos.TempIMGAddressModel;
import com.badibadi.infos.TypeId;
import com.badibadi.mytools.CalendarTools;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.Convert;
import com.badibadi.mytools.Dialog;
import com.badibadi.mytools.FriendsTool;
import com.badibadi.mytools.MyThreadTool;
import com.badibadi.mytools.Utils;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.R.layout;
import com.badibadi.uniclubber.R.menu;
import com.google.gson.JsonArray;
import com.libjph.util.JsonUtil;
import com.libjph.util.StringUtil;
//import com.lidroid.xutils.util.LogUtils;
import com.view.my_view.MyGridView;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.CalendarContract.Attendees;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 2014-11-11 个人+俱乐部--修改记录（记）显示数据接口----POST record_first_uppic_settings
 * Service_img_address
 * 
 * @param $aid
 *            ;// 记录(记)的id
 * @param $uid
 *            （登陆者用户ID）----editClubArticleShowModel AddCity
 */
public class ModifyTheRecordDanjiActivity extends AddingRecordFirstActivity// setOnDeletePictrueClistener
		implements OnClickListener {
	// 一般标签的列表个数不能超过40的，这里为了防止问题，设为了80.
	private int list_de_size = 80;
	ModifyRecordDanjiModel modifyRecordDanjiModel;
	String aid;
	String dijiji;// 第几记
	private MyGridView up_img_item_image;
	TextView startTime, endTime;
	EditText image_description;// 内容
	protected static final String TAG = "ModifyTheRecordDanjiActivity";

	private LinearLayout button_address;// 地址

	private Results results, results22;
	private String record_dan_num;

	private String cid;// 如果是俱乐部的记录，需要传当前俱乐部的id
	private String rid;// 传入当前记录篇的id

	private Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 3000:

				break;
			case 1:
				Utils.ExitPrgress(ModifyTheRecordDanjiActivity.this);
				Utils.showMessage(ModifyTheRecordDanjiActivity.this,
						getResources().getString(R.string.l_net_error));
				break;
			case 10:
				// Utils.ExitPrgress(ModifyTheRecordDanjiActivity.this);
				// Utils.showMessage(ModifyTheRecordDanjiActivity.this,
				// "网络连接失败");
				//    
				// initView();
				try {
					recordHeadJiNum(rid);
				} catch (Exception e) {
					   
				}

				break;
			case 3:
				Utils.ExitPrgress(ModifyTheRecordDanjiActivity.this);
				Utils.showMessage(ModifyTheRecordDanjiActivity.this,
						getResources().getString(R.string.SystemError));
				break;

			case 4:
				Utils.ExitPrgress(ModifyTheRecordDanjiActivity.this);

				if (results.isRet() == true) {
					try {
						Utils.showMessage(ModifyTheRecordDanjiActivity.this,
								getResources().getString(R.string.l_xb53));
						returnUp();
					} catch (Exception e) {
						// TODO: handle exception
					}
					Constants.is_shuaxin = true;
					finish();
				} else {
					try {
						Utils.showMessage(ModifyTheRecordDanjiActivity.this,
								getResources().getString(R.string.l_xb95));

					} catch (Exception e) {
						// TODO: handle exception
					}

				}
				break;
			case 5:
				Utils.ExitPrgress(ModifyTheRecordDanjiActivity.this);
				Utils.showMessage(ModifyTheRecordDanjiActivity.this,
						getResources().getString(R.string.l_xa10));
				break;
			case 6:
				Utils.ExitPrgress(ModifyTheRecordDanjiActivity.this);
//				   
				record_dan_num = results22.getRetmsg();
				initView();
				// Intent intent = new Intent(ModifyTheRecordDanjiActivity.this,
				// AddingRecordFirstActivity.class);
				// intent.putExtra("is_newcreate", "no");
				// intent.putExtra("rid_main", "");//当前记录id
				// intent.putExtra("ji_num", "");
				// Integer.valueOf(results22.getRetmsg());
				break;
			default:
				break;
			}
		}
	};

	private void returnUp() {
		Intent intent = new Intent();
		intent.setClass(ModifyTheRecordDanjiActivity.this,
				LogReadingDanjiActivity.class);
		intent.putExtra("aid", aid);
		startActivity(intent);
		ModifyTheRecordDanjiActivity.this.finish();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		aid = getIntent().getStringExtra("aid");
		dijiji = getIntent().getStringExtra("dijiji");
		cid = getIntent().getStringExtra("cid");
		rid = getIntent().getStringExtra("rid");

//		   
		// rid
		init();
		editArticleShow();
		// setContentView(R.layout.activity_modify_the_record_danji);

	}

	@Override
	protected void init() {
		// TODO Auto-generated method stub
		super.init();
		Constants.is_shuaxin = false;
		this.findViewById(R.id.ll_fenxiangdao).setVisibility(View.GONE);
		this.findViewById(R.id.ll_fenxiang).setVisibility(View.GONE);
		// 提交
		// this.findViewById(R.id.record_first_uppic_settings).setOnClickListener(
		// new View.OnClickListener() {
		//
		// @Override
		// public void onClick(View v) {
		// // TODO Auto-generated method stub
		// //    
		// // Toast.makeText(ModifyTheRecordDanjiActivity.this,
		// // "成功",
		// // 1).show();
		//
		// }
		// });
//		   

		this.findViewById(R.id.return_btn).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						returnUp();
					}
				});
	}

	// private void AddCity(String name, LinearLayout v) {
	// Button button = new Button(ModifyTheRecordDanjiActivity.this);
	// button.setText(name);
	// button.setBackgroundResource(R.drawable.shape_blue_circular_bead_100);
	// button.setFocusable(false);
	// button.setFocusableInTouchMode(false);
	// button.setTextColor(getResources().getColor(R.color.white));
	// v.addView(button);
	// }
	/**
	 * 初始化界面上的
	 */
	protected void initView() {
		// TODO Auto-generated method stub
		// //下面是@好友的
		// listObj_main = getListObj_main();
		// friend_Item_Adapter = getFriend_Item_Adapter();
		//
		// listObj_main=new ArrayList<MyFriendsModel>();
		String split_fenge = "\\+\\+\\+\\-\\-\\-\\+\\+\\+";
		String infos = modifyRecordDanjiModel.getParticipator();
		if (!StringUtil.isNullOrEmpty(infos)) {

			if (infos.equals(split_fenge)) {

			} else {
				String infos2 = infos.substring(1, infos.length());
				String[] infos3 = infos2.split("@");
				for (int i = 0; i < infos3.length; i++) {
					MyFriendsModel friendsModel = new MyFriendsModel();
					friendsModel.setNickName(infos3[i]);
					friendsModel.setJudge(true);
					getListObj_main().add(friendsModel);
				}
				getFriend_Item_Adapter().notifyDataSetChanged();
			}

		}
		if (!StringUtil.isNullOrEmpty(modifyRecordDanjiModel.getTypeid())) {
			if (!modifyRecordDanjiModel.getTypeid().equals(split_fenge)) {

				// imageAttribute.set
//				   
//						+ modifyRecordDanjiModel.getTypeid());
				String typeid[] = modifyRecordDanjiModel.getTypeid().split(
						split_fenge);

//				   

				String attachment[] = modifyRecordDanjiModel.getAttachment()
						.split(split_fenge);
//				   
				// 站点地址
				String address[] = modifyRecordDanjiModel.getZhan_name().split(
						split_fenge);
//				   
				// 描述
				String info[] = null;
				if (modifyRecordDanjiModel.getInfo() != null) {
					info = modifyRecordDanjiModel.getInfo().split(split_fenge);
				}

//				   
				// 相册id
				String photo_id[] = modifyRecordDanjiModel.getPhoto_id().split(
						split_fenge);
//				   
				String zhan_name[] = modifyRecordDanjiModel.getZhan_name()
						.split(split_fenge);
//				   
				String map_x[] = modifyRecordDanjiModel.getMap_x().split(
						split_fenge);
//				   
				String map_y[] = modifyRecordDanjiModel.getMap_y().split(
						split_fenge);
//				   
				String imgParticipator[] = modifyRecordDanjiModel
						.getImgParticipator().split(split_fenge);
//				   

				String path[] = modifyRecordDanjiModel.getPath().split(
						split_fenge);
				String is_show[] = modifyRecordDanjiModel.getIs_show().split(
						split_fenge);
				// String
				for (int i = 0; i < zhan_name.length; i++) {
					// 封装typeid
//					   
					ImageAttribute imageAttribute = new ImageAttribute();
					String typeids[] = typeid[i].split(",");
					Map<Integer, String> map = new HashMap<Integer, String>();
//					   
					for (int j = 0; j < typeids.length; j++) {
						int k = j + list_de_size;
						map.put(k, typeids[j]);
						imageAttribute.setBiaoqian_num(list_de_size * 2);
						// if(imageAttribute.getBiaoqian_num()==0)
						// {
						// imageAttribute.setBiaoqian_num(list_de_size);
						// }else
						// {
						// int b=imageAttribute.getBiaoqian_num()+1;
						// imageAttribute.setBiaoqian_num(b);
						// }
					}
					imageAttribute.setBiaoqian_map(map);
					try {
						imageAttribute.setLaiyuan(attachment[i]);
					} catch (Exception e) {
						// TODO: handle exception
						imageAttribute.setLaiyuan("");
					}
					try {
						imageAttribute.setAbsolute_address(address[i]);
					} catch (Exception e) {
						// TODO: handle exception
						imageAttribute.setAbsolute_address("");
					}
					try {
						imageAttribute.setInfo(info[i]);
					} catch (Exception e) {
						// TODO: handle exception
						imageAttribute.setInfo("");
					}
					try {
						imageAttribute.setXiangceid(photo_id[i]);
					} catch (Exception e) {
						// TODO: handle exception
					}
					try {

						ArrayList<String> img = new ArrayList<String>();
						img.add(path[i]);
						imageAttribute.setService_img_address(img);

					} catch (Exception e) {
						// TODO: handle exception
					}
					try {
						ArrayList<String> img = new ArrayList<String>();
						String b = "\\/Public";
						String noqianzui[] = path[i].split(b);

						for (int s = 0; s < noqianzui.length; s++) {
//							   
//									+ noqianzui[s]);

							if (!noqianzui[s].equals("")) {
								img.add(b + noqianzui[s]);
							}

						}
						imageAttribute.setArrayList(img);
					} catch (Exception e) {
						// TODO: handle exception
					}

					try {
						imageAttribute.setAddress_weidu(map_x[i]);

					} catch (Exception e) {
						// TODO: handle exception
						imageAttribute.setAddress_weidu("");
					}
					try {
						imageAttribute.setAddress_jingdu(map_y[i]);
					} catch (Exception e) {
						// TODO: handle exception
						imageAttribute.setAddress_jingdu("");
					}

					try {
						imageAttribute.setCanyu_persons(imgParticipator[i]);
					} catch (Exception e) {
						// TODO: handle exception
						imageAttribute.setCanyu_persons("");
					}
					try {
						imageAttribute.setZhan_num("" + (i + 1));
					} catch (Exception e) {
						// TODO: handle exception
					}
					try {
						imageAttribute.setIs_displaydongtai("" + is_show[i]);
					} catch (Exception e) {
						// TODO: handle exception
					}
					attributes.add(imageAttribute);
//					   
//					   
					addressModels = new ArrayList<TempIMGAddressModel>();
					if (imageAttribute.getArrayList() != null
							&& !imageAttribute.getArrayList().isEmpty()) {
						for (int j = 0; j < imageAttribute.getArrayList()
								.size(); j++) {
							TempIMGAddressModel model = new TempIMGAddressModel();
							model.setImg_address(imageAttribute.getArrayList()
									.get(j));

							addressModels.add(model);
						}
					}
//					   
					addressModels_main.addAll(addressModels);
//					   

					adapter.notifyDataSetChanged();

					button_address = (LinearLayout) findViewById(R.id.button_address);
//					   
//							+ "2=" + button_address);
					Utils.AddCity(ModifyTheRecordDanjiActivity.this,
							imageAttribute.getAbsolute_address(),
							button_address);

				}
			}

			DeletePicture();

		}

		// if (!StringUtil.isNullOrEmpty(modifyRecordDanjiModel.getZhan_name()))
		// {
		// button_address = (LinearLayout) findViewById(R.id.button_address);
		// String zhan_name = modifyRecordDanjiModel.getZhan_name();
		// String[] zhan = zhan_name.split("\\+\\+\\+\\-\\-\\-\\+\\+\\+");
		// for (int i = 0; i < zhan.length; i++) {
		//    
		// AddCity(zhan[i], button_address);
		// }
		// }
//		   
		TextView title = (TextView) this.findViewById(R.id.title);
		// 第几记
		// title.setText(getResources().getString(R.string.l_xb102)
		// + modifyRecordDanjiModel.getR_num()// Convert.convert()
		// + getResources().getString(R.string.l_xb103));
		title.setText(getResources().getString(R.string.l_xb102) + dijiji// Convert.convert()
				+ getResources().getString(R.string.l_xb103));
		// 名称
		final EditText record_name = (EditText) this
				.findViewById(R.id.record_name);
		record_name.setHint(getResources().getString(R.string.l_xb104)
				+ modifyRecordDanjiModel.getR_num()// Convert.convert()
				+ getResources().getString(R.string.l_xb105));

		record_name.setText("" + modifyRecordDanjiModel.getTitle());
//		   
		image_description = (EditText) this
				.findViewById(R.id.image_description);
		image_description.setText("" + modifyRecordDanjiModel.getContent());
		startTime = (TextView) this.findViewById(R.id.startTime);
		// startTime.setOnClickListener(this);
		endTime = (TextView) this.findViewById(R.id.endTime);
		// endTime.setOnClickListener(this);

		startTime.setText("" + modifyRecordDanjiModel.getStart_time());
		endTime.setText("" + modifyRecordDanjiModel.getEnd_time());
		// zhan_name
		if (Integer.valueOf(dijiji) < Integer.valueOf(record_dan_num)) {
			this.findViewById(R.id.record_first_new_add_record).setVisibility(
					View.GONE);
		} else {
			this.findViewById(R.id.record_first_new_add_record)
					.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							Intent intent = new Intent(
									ModifyTheRecordDanjiActivity.this,
									AddingRecordFirstActivity.class);
							intent.putExtra("is_newcreate", "no");
							intent.putExtra("rid_main", Integer.valueOf(rid));
							if (cid != null) {
								intent.putExtra("cid", cid);
							}
//							   
							// intent.putExtra("ji_num",
							// Integer.valueOf(record_dan_num));
							startActivity(intent);
							ModifyTheRecordDanjiActivity.this.finish();
						}
					});
		}
		// 提交
		this.findViewById(R.id.record_first_uppic_settings).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						//    
						// Toast.makeText(ModifyTheRecordDanjiActivity.this,
						// "成功",
						// 1).show();

						// aid="1";
						// String
						// uid=Utils.getUid(ModifyTheRecordDanjiActivity.this);
						// cid="1";
						String tit = null, pers = null, con = null;
						is_new_add = false;
						tit = record_name.getText().toString().trim();// 记的名称
						con = image_description.getText().toString().trim();// 内容
						pers = FriendsTool.BackAllResult("sdf",
								getListObj_main());// @的haoyou
						if (Utils.Judge_Time(startTime.getText().toString()
								.trim(), endTime.getText().toString().trim())) {
							// Toast.makeText(getApplicationContext(), "新增一记",
							// 0).show();
							if (!StringUtil.isNullOrEmpty(tit)
									&& !StringUtil.isNullOrEmpty(con)) {

								try {
									// add_article(
									// fengzhuang_article(
									// Constants.START_TIME,
									// Constants.END_TIME,
									// tit, pers, con),
									// fengzhuang_img_infos(),
									// rid_main);
									editArticle(
											aid,
											Utils.getUid(ModifyTheRecordDanjiActivity.this),
											cid,
											fengzhuang_article(startTime
													.getText().toString()
													.trim(), endTime.getText()
													.toString().trim(), tit,
													pers, con),
											fengzhuang_img_infos());
								} catch (JSONException e) {
									// TODO Auto-generated catch block
									   
								}

							} else {
								Toast.makeText(
										getApplicationContext(),
										getResources().getString(
												R.string.l_plese_enterthe_data),
										0).show();
							}
						} else {
							Toast.makeText(getApplicationContext(),
									getResources().getString(R.string.l_xb27),
									0).show();
						}

					}
				});
	}

	public void recordHeadJiNum(final String recordId) {
		// Utils.showPrgress(ModifyTheRecordDanjiActivity.this);
		MyThreadTool.fixedThreadPool.execute(new Runnable() {
			@Override
			public void run() {
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("recordId", recordId);
				String content = Utils.sendRequest(map, Constants.BadiUrl_1
						+ "record/recordHeadJiNum");
				if (content != null) {
					results22 = Utils.checkResult_NNN(getApplicationContext(),
							content);
//					   ("当前记录有多少记:" + content);
					if (results22 != null
							&& !results22.getRetmsg().equals("null")
							&& results22.isRet()) {
						handler.sendEmptyMessage(6);
					} else {
						handler.sendEmptyMessage(5);
					}
				} else {
					handler.sendEmptyMessage(1);
				}
			}
		});
	}

	/**
	 * 删除图片重寫的接口
	 */
	private void DeletePicture() {
		// TODO Auto-generated method stub
		// 重写长按删除图片
		setOnDeletePictrueClistener(new DeletePicture() {

			@Override
			public void deletePictrue(int position,
					List<TempIMGAddressModel> addressModels_main,
					List<ImageAttribute> attributes) {
				// TODO Auto-generated method stub
				String path = addressModels_main.get(position).getImg_address();// 这是一张图片的路径(要移除的那张图片的路径)

//				LogUtils.w("path==" + path);
				String path2 = path.substring(1);
				int num = -1;// 确定是第几个站点的图片
				for (int i = 0; i < attributes.size(); i++) {
//					LogUtils.w("1");
					// 服务器的地址 /public
					String p = attributes.get(i).getService_img_address()
							.get(0);
//					LogUtils.w("p=" + p);
					if (p.indexOf(path2) != -1) {
//						LogUtils.w("2");
						num = i + 1;
						String tt = attributes.get(i).getService_img_address()
								.get(0).replace(path2, "");// 替换要删除的那个地址
//						LogUtils.w("tt=" + tt);
						attributes.get(i).getService_img_address().set(0, tt);
						if (attributes.get(i).getService_img_address().get(0)
								.equals("")) {// &&
												// attributes.size()!=1如果后面有其他问题在这里改
							attributes.remove(i);
//							LogUtils.w("3");
						}
					}
				}
				addressModels_main.remove(position);
				getAdapter().notifyDataSetChanged();

			}
		});
	}

	/**
	 * 提交
	 * 
	 * @param aid
	 * @param uid
	 * @param cid
	 * @param article
	 * @param img
	 */
	private void editArticle(final String aid, final String uid,
			final String cid, final JSONObject article, final JSONObject img) {
		Utils.showPrgress(ModifyTheRecordDanjiActivity.this);
		MyThreadTool.fixedThreadPool.execute(new Runnable() {
			@Override
			public void run() {
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("aid", aid);
				map.put("uid", uid);
				if (cid != null)
					map.put("cid", cid);
				else {
					map.put("cid", "0");
				}
				map.put("article", article);
				map.put("img", img);
				if (cid != null) {
					map.put("cid", cid);
				}
				//    ("新的一记提交上去的数据" + map.toString());
//				   
				String content = Utils.sendRequest(map, Constants.BadiUrl_1
						+ "record/editArticle");
//				   
				//    ("新的一记返回的结果是：" + content);

				if (content != null) {
					results = Utils.checkResult_NNN(getApplicationContext(),
							content);
					if (results != null && !results.getRetmsg().equals("null")) {
						//    ("测试结果是:" + results.getRetmsg());
//						   
						handler.sendEmptyMessage(4);
					} else {
						handler.sendEmptyMessage(3);
					}
				} else {
					handler.sendEmptyMessage(1);
				}
			}
		});
	}

	/**
	 * 返回记的内容
	 * 
	 * @return
	 * @throws JSONException
	 */
	private JSONObject fengzhuang_article(String stime, String etime,
			String title, String person, String content) throws JSONException {
		JSONObject object = new JSONObject();
		object.put("start_time", stime);
		object.put("end_time", etime);
		// object.put("uid", Utils.getUid(ModifyTheRecordDanjiActivity.this));
		object.put("title", title);
		//    
		// + addressModels_main.get(0).getImg_address());
		// if (!addressModels_main.isEmpty()) {
		// // if (addressModels_main.get(0).getImg_address() != null) {
		// object.put("image", "" + addressModels_main.get(0).getImg_address());
		//    
		// // } else {
		// // object.put("image",
		// // "/Public/Uploads/2014-04/139709403754812.png");
		// // }
		// } else {
		// object.put("image", "/Public/Uploads/2014-04/139709403754812.png");
		// }
		object.put("participator", person);
		object.put("content", content);
		return object;
	}

	private JSONObject fengzhuang_img_infos() throws JSONException {
		// JSONArray array_main = new JSONArray();
		JSONObject object = new JSONObject();
		object.put("typeid", fengzhuang_typeid());
		//    
		object.put("attachment", fengzhuang_attachment());
		//    
		object.put("address", fengzhuang_address());
		//    
		object.put("info", fengzhuang_info());
		//    
		object.put("photo_id", fengzhuang_photo_id());
		//    
		object.put("map_x", fengzhuang_map_x());
		//    
		object.put("map_y", fengzhuang_map_y());
		//    
		object.put("zhan_num", fengzhuang_zhan_num());
		//    
		object.put("path", fengzhuang_path());
//		   
		object.put("is_show", fengzhuang_is_show());
		//    
		object.put("participator", fengzhuang_participator());
		//    
		// array_main.put(object);
		//    
		return object;
	}

	// 封装typeid
	protected JSONArray fengzhuang_typeid() throws JSONException {
		JSONArray object;
		object = new JSONArray();
		for (int i = 0; i < attributes.size(); i++) {
			String t = "";
//			   ("数" + i);
			//    ("数量是" + attributes.get(i).getBiaoqian_num());
			if (attributes.get(i).getBiaoqian_map() != null
					&& !attributes.get(i).getBiaoqian_map().isEmpty()) {
//				   ("数" + attributes.get(i).getBiaoqian_num());
				for (int j = 0; j < attributes.get(i).getBiaoqian_num(); j++) {
					if (attributes.get(i).getBiaoqian_map().get(j) != null) {
						// t += attributes.get(i).getBiaoqian_map().get(j) +
						// ",";
						object.put(attributes.get(i).getBiaoqian_map().get(j));
					}
				}

			}
		}
//		   ("打印:" + object.toString());
		return object;
		// StringBuffer t = new StringBuffer("{");
		//    ("typeid=" + t.toString());
		// for (int i = 0; i < attributes.size(); i++) {
		// //    ("数" + i);
		// //    ("数量是" + attributes.get(i).getBiaoqian_num());
		//
		// if (attributes.get(i).getBiaoqian_map() != null
		// && !attributes.get(i).getBiaoqian_map().isEmpty()) {
		// //    ("数" +
		// // attributes.get(i).getBiaoqian_num());
		// t.append("\"" + i + "\"" + ":" + "\"");
		// for (int j = 0; j < attributes.get(i).getBiaoqian_num(); j++) {
		// if (attributes.get(i).getBiaoqian_map().get(j) != null) {
		//
		// // t += attributes.get(i).getBiaoqian_map().get(j) +
		// // ",";
		// t.append(attributes.get(i).getBiaoqian_map().get(j)
		// + ",");
		//    ("typeid1=" + t.toString());
		// }
		//    ("typeid2=" + t.toString());
		// }
		// if (!t.equals("{")) {
		// String m = (String) t.toString().substring(0,
		// t.length() - 1);
		// t = new StringBuffer(m);
		// }
		// t.append("\"" + ",");
		//    ("typeid3=" + t.toString());
		// // if (!t.equals("")) {
		// // // object.put(i + "", quchu_zuihou(t));
		// // }
		// }
		// }
		// if (!t.equals("{") && !t.equals("") && t!=null) {
		// String m = (String) t.toString().substring(0, t.length() - 2);
		// t = new StringBuffer(m);
		//    ("typeid4=" + t.toString());
		// }
		// t.append("\"}");
		//    ("typeid转化后5=" + t.toString());
		// //    ("打印:" + object.toString());
		// return t.toString();
	}

	protected JSONArray fengzhuang_attachment() throws JSONException {
		// TODO Auto-generated method stub

		JSONArray object = null;
		object = new JSONArray();
		for (int i = 0; i < attributes.size(); i++) {
			object.put(attributes.get(i).getLaiyuan());
		}
//		   (object.toString());
		return object;

		// StringBuffer buff = new StringBuffer("{");
		// for (int i = 0; i < attributes.size(); i++) {
		// buff.append("\"" + i + "\":" + "\""
		// + attributes.get(i).getLaiyuan() + "\",");
		//
		// }
		// if (!buff.equals("{")) {
		// String m = (String) buff.toString().substring(0, buff.length() - 1);
		// buff = new StringBuffer(m);
		// }
		// buff.append("}");
		//    
		// return buff.toString();
	}

	protected JSONArray fengzhuang_address() throws JSONException {
		// TODO Auto-generated method stub
		JSONArray object = null;
		object = new JSONArray();
		for (int i = 0; i < attributes.size(); i++) {
			// object.put("" + i, attributes.get(i).getAbsolute_address());
			object.put(attributes.get(i).getAbsolute_address());
		}
		//    (object.toString());
		return object;
		// StringBuffer buff = new StringBuffer("{");
		// for (int i = 0; i < attributes.size(); i++) {
		// buff.append("\"" + i + "\":" + "\""
		// + attributes.get(i).getAbsolute_address() + "\",");
		//
		// }
		// if (!buff.equals("{")) {
		// String m = (String) buff.toString().substring(0, buff.length() - 1);
		// buff = new StringBuffer(m);
		// }
		// buff.append("}");
		//    
		//
		// return buff.toString();
	}

	protected JSONArray fengzhuang_info() throws JSONException {
		// TODO Auto-generated method stub
		JSONArray object = null;
		object = new JSONArray();
		for (int i = 0; i < attributes.size(); i++) {
			if (attributes.get(i).getInfo() == null) {
				object.put("");
			} else {
				object.put(attributes.get(i).getInfo());
			}
		}
//		   (object.toString());
		return object;
		// StringBuffer buff = new StringBuffer("{");
		// for (int i = 0; i < attributes.size(); i++) {
		// buff.append("\"" + i + "\":" + "\"" + attributes.get(i).getInfo()
		// + "\",");
		//
		// }
		// if (!buff.equals("{")) {
		// String m = (String) buff.toString().substring(0, buff.length() - 1);
		// buff = new StringBuffer(m);
		// }
		// buff.append("}");
		//    
		// return buff.toString();
	}

	protected JSONArray fengzhuang_photo_id() throws JSONException {
		// TODO Auto-generated method stub
		JSONArray object = null;
		object = new JSONArray();
		for (int i = 0; i < attributes.size(); i++) {
			object.put(attributes.get(i).getXiangceid());
		}
//		   (object.toString());
		return object;
		// StringBuffer buff = new StringBuffer("{");
		// for (int i = 0; i < attributes.size(); i++) {
		// buff.append("\"" + i + "\":" + "\""
		// + attributes.get(i).getXiangceid() + "\",");
		//
		// }
		// if (!buff.equals("{")) {
		// String m = (String) buff.toString().substring(0, buff.length() - 1);
		// buff = new StringBuffer(m);
		// }
		// buff.append("}");
		//    
		// return buff.toString();
	}

	protected JSONArray fengzhuang_map_x() throws JSONException {
		// TODO Auto-generated method stub
		JSONArray object = null;
		object = new JSONArray();
		for (int i = 0; i < attributes.size(); i++) {
			object.put(attributes.get(i).getAddress_weidu());
		}
//		   (object.toString());
		return object;
		// StringBuffer buff = new StringBuffer("{");
		// for (int i = 0; i < attributes.size(); i++) {
		// buff.append("\"" + i + "\":" + "\""
		// + attributes.get(i).getAddress_weidu() + "\",");
		//
		// }
		// if (!buff.equals("{")) {
		// String m = (String) buff.toString().substring(0, buff.length() - 1);
		// buff = new StringBuffer(m);
		// }
		// buff.append("}");
		//    
		// return buff.toString();
	}

	protected JSONArray fengzhuang_map_y() throws JSONException {
		// TODO Auto-generated method stub
		JSONArray object = null;
		object = new JSONArray();
		for (int i = 0; i < attributes.size(); i++) {
			object.put(attributes.get(i).getAddress_jingdu());
		}
//		   (object.toString());
		return object;
		// StringBuffer buff = new StringBuffer("{");
		// for (int i = 0; i < attributes.size(); i++) {
		// buff.append("\"" + i + "\":" + "\""
		// + attributes.get(i).getAddress_jingdu() + "\",");
		//
		// }
		// if (!buff.equals("{")) {
		// String m = (String) buff.toString().substring(0, buff.length() - 1);
		// buff = new StringBuffer(m);
		// }
		// buff.append("}");
		//    
		// return buff.toString();

	}

	protected JSONArray fengzhuang_zhan_num() throws JSONException {
		// TODO Auto-generated method stub
		JSONArray object = null;
		object = new JSONArray();
		for (int i = 0; i < attributes.size(); i++) {
			// object.put(attributes.get(i).getZhan_num());
			object.put("" + (i + 1));
			// LogUtils.i("zhan_num="+attributes.get(i).getZhan_num());
		}
//		   (object.toString());
		return object;
		// StringBuffer buff = new StringBuffer("{");
		// for (int i = 0; i < attributes.size(); i++) {
		// buff.append("\"" + i + "\":" + "\""
		// + attributes.get(i).getZhan_num() + "\",");
		//
		// }
		// if (!buff.equals("{")) {
		// String m = (String) buff.toString().substring(0, buff.length() - 1);
		// buff = new StringBuffer(m);
		// }
		// buff.append("}");
		//    
		// return buff.toString();
	}

	private JSONArray fengzhuang_path() throws JSONException {
		JSONArray object = null;
		object = new JSONArray();
		for (int i = 0; i < attributes.size(); i++) {
			if (attributes.get(i).getService_img_address() != null
					&& !attributes.get(i).getService_img_address().isEmpty()) {
				String pa = "";
				for (int j = 0; j < attributes.get(i).getService_img_address()
						.size(); j++) {
					pa += attributes.get(i).getService_img_address().get(j);
				}
				object.put(pa);
			}
		}
//		   (object.toString());
		return object;
		// TODO Auto-generated method stub
		// JSONObject object = null;
		// object = new JSONObject();
		// for (int i = attributes.size() - 1; i >= 0; i--) {
		// if (attributes.get(i).getService_img_address() != null
		// && !attributes.get(i).getService_img_address().isEmpty()) {
		// String pa = "";
		// for (int j = 0; j < attributes.get(i).getService_img_address()
		// .size(); j++) {
		// pa += attributes.get(i).getService_img_address().get(j);
		// }
		// object.put("" + i, pa);
		// }
		// }
		//    (object.toString());

		// StringBuffer buff = new StringBuffer("{");
		// for (int i = 0; i < attributes.size(); i++) {
		// buff.append("\"" + i + "\":" + "\""
		// + attributes.get(i).getService_img_address() + "\",");
		//
		// }
		// if (!buff.equals("{")) {
		// String m = (String) buff.toString().substring(0, buff.length() - 1);
		// buff = new StringBuffer(m);
		// }
		// buff.append("}");
		//    
		//
		// if (!buff.equals("{")) {
		// String m = (String) buff.toString();
		//    
		// String o = m.replaceAll("\\[", "");
		//    
		// String n = o.replaceAll("\\]", "");
		//    
		// buff = new StringBuffer(n);
		// }
		// return buff.toString();
	}

	protected JSONArray fengzhuang_is_show() throws JSONException {
		// TODO Auto-generated method stub
		JSONArray object = null;
		object = new JSONArray();
		for (int i = 0; i < attributes.size(); i++) {
			object.put(attributes.get(i).getIs_displaydongtai());
		}
//		   (object.toString());
		return object;
		// StringBuffer buff = new StringBuffer("{");
		// for (int i = 0; i < attributes.size(); i++) {
		// buff.append("\"" + i + "\":" + "\""
		// + attributes.get(i).getIs_displaydongtai() + "\",");
		//
		// }
		// if (!buff.equals("{")) {
		// String m = (String) buff.toString().substring(0, buff.length() - 1);
		// buff = new StringBuffer(m);
		// }
		// buff.append("}");
		//    
		// return buff.toString();
	}

	protected JSONArray fengzhuang_participator() throws JSONException {
		// TODO Auto-generated method stub
		JSONArray object = null;
		object = new JSONArray();
		for (int i = 0; i < attributes.size(); i++) {
			object.put(attributes.get(i).getCanyu_persons());
//			   
		}
//		   (object.toString());
		return object;
		// StringBuffer buff = new StringBuffer("{");
		// for (int i = 0; i < attributes.size(); i++) {
		// buff.append("\"" + i + "\":" + "\""
		// + attributes.get(i).getCanyu_persons() + "\",");
		//
		// }
		// if (!buff.equals("{")) {
		// String m = (String) buff.toString().substring(0, buff.length() - 1);
		// buff = new StringBuffer(m);
		// }
		// buff.append("}");
		//    
		// return buff.toString();
	}

	/*
	 * 个人+俱乐部--修改记录（记）提交数据----POST
	 * 
	 * @param $aid 修改的记录（记）ID
	 * 
	 * @param $uid 用户id,
	 * 
	 * @param $cid 俱乐部ID,
	 * 
	 * @param $article =array( 'start_time'=>'2014-8-29开始时间' ,
	 * 'end_time'=>'2014-8-30结束时间', 'title'=>'我知道我的未来不是梦 标题',
	 * 'image'=>"/Public/Uploads/2014-04/139709403754812.png 记的封面图",
	 * APP端不能上传记的封面图 'content'=>"大汉王朝即将在此建都 内容",
	 * "participator"=>@用户昵称1@用户昵称2..); 记录的参与者
	 * 
	 * @param $img=array( //注意：这里只传递新增的站点信息
	 * 'typeid'=>array('103,104,105','102,101,103'), 'attachment'
	 * =>array('照片来源1','照片来源2'), 'address' =>array("地址1","地址2")照片的地址 , 'info'
	 * =>array("描述1",'描述2'), 'photo_id'=>array('上传到那个相册1','上传到那个相册2'),
	 * 'map_x'=>array('纬度1','纬度2'), 'map_y'=>array('经度1','经度2'),
	 * 'zhan_num'=>array("1",'2'), 'path'=>'照片的路劲 最多不超过8张 格式array(
	 * '/Public/Uploads/2014-08/53ffe7a93910b.jpg/Public/Uploads/2014-08/53ffe7a9654ab.png','/Public/Uploads/2014-08/53ffe7a93910b.jpge/Public/Uploads/2014-08/53ffe7a9654ab.pnge')),
	 * 'is_show'=>array('0：否，1：是','0：否，1：是'),
	 * "participator"=>array('@用户昵称1@用户昵称2..','@用户昵称1@用户昵称2..')) ;
	 */
	/*
	 * 个人+俱乐部--修改记录（记）显示数据接口----POST
	 * 
	 * @param $aid;// 记录(记)的id
	 * 
	 * @param $uid （登陆者用户ID）----editClubArticleShowModel
	 */
	private void editArticleShow() {
		Utils.showPrgress(ModifyTheRecordDanjiActivity.this);
		MyThreadTool.fixedThreadPool.execute(new Runnable() {
			@Override
			public void run() {
				Map<String, Object> map = new HashMap<String, Object>();

				map.put("aid", aid);
				map.put("uid", Utils.getUid(ModifyTheRecordDanjiActivity.this));
				String content = Utils.sendRequest(map, Constants.BadiUrl_1
						+ "record/editArticleShow");
//				   
				if (content != null) {
					Results results = Utils.checkResult_NNN(
							ModifyTheRecordDanjiActivity.this, content);
					if (results != null && !results.getRetmsg().equals("null")) {
//						   
						try {
							modifyRecordDanjiModel = JsonUtil
									.getEntityByJsonString(results.getRetmsg(),
											ModifyRecordDanjiModel.class);

							// showDisscuss=discuss.getDiscu().get(0);
							// activityReadingModel=JsonUtil.getEntityByJsonString(results.getRetmsg(),
							// ActivityReadingModel.class);
							handler.sendEmptyMessage(10);
						} catch (Exception e) {
							   
//							   
						}
					} else {
						handler.sendEmptyMessage(3);
					}
				} else {
					handler.sendEmptyMessage(1);
				}
			}
		});
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub

		if (keyCode == KeyEvent.KEYCODE_BACK) {
			returnUp();
		}

		return super.onKeyDown(keyCode, event);
	}

	// /**
	// * 俱乐部--修改记的信息接口 ----POST
	// * @param $article=array(
	// * 'uid'=>'修改者的id',
	// * 'aid'=>'修改的记的id,
	// * 'title'=>'记的标题',
	// * 'start_time'=>'开始时间', 2014-11-07
	// * 'end_time'=>'结束时间', 2014-11-07
	// * 'content'=>"内容",
	// * 'image_id'=>'照片的id',
	// * "participator"=>@的人);
	// */
	// public void editArticle(String uid,String aid,String title,String
	// start_time,String end_time,String content,String imgage_id,String
	// participator)
	// {
	// // Map<String, >
	//
	// }

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		super.onClick(v);

	}
}
